package com.ll.studentservice.controller;


import com.ll.commonUtils.R;
import com.ll.studentservice.entity.EduGrade;
import com.ll.studentservice.service.EduGradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ll
 * @since 2020-12-08
 */
@Api(description = "年级信息增删查改API") //swagger界面提示
@RestController
@RequestMapping("/studentservice/edugrade")
public class EduGradeController {

    @Autowired
    private EduGradeService eduGradeService;

    @ApiOperation(value = "添加年级信息") //swagger界面提示
    @PostMapping("addGradeInfo")
    public R addGradeInfo(@RequestBody EduGrade eduGrade){
        boolean save = eduGradeService.save(eduGrade);

        return save ? R.ok().message("添加成功") : R.error().message("添加失败");
    }

    @ApiOperation(value = "查询所有年级信息") //swagger界面提示
    @GetMapping("getAllGradeInfo")
    public R getAllGradeInfo(){
        List<EduGrade> list = eduGradeService.list(null);
        return R.ok().data("AllGradeInfoList", list);
    }

    @ApiOperation(value = "删除某个年级信息") //swagger界面提示
    @DeleteMapping("deleteGradeInfo/{gradeId}")
    public R deleteGradeInfo(@PathVariable String gradeId){
        boolean flag = eduGradeService.removeById(gradeId);

        System.out.println("删除某个年级信息: " + flag);

        return R.ok().message("删除成功");
    }





}

